package com.sh.one;

import com.sh.model.ServiceMetaInfo;
import com.sh.one.impl.ConsistentHashLoaderBalancer;
import com.sh.one.impl.RoundRobinLoadBalancer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
      LoadBalancer loadBalancer = new ConsistentHashLoaderBalancer();
        List<ServiceMetaInfo> serviceList = new ArrayList<>();
        serviceList.add(new ServiceMetaInfo("Service3"));

        serviceList.add(new ServiceMetaInfo("Service2"));
        serviceList.add(new ServiceMetaInfo("Service1"));

        Map<String, Object> requestParams = new HashMap<>();

        // 模拟多次请求，查看负载均衡效果
        for (int i = 0; i < 10; i++) {
            ServiceMetaInfo selectedService = loadBalancer.select(requestParams, serviceList);
            System.out.println("Selected service: " + selectedService.getServiceName());
        }
    }
}